using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
using SubSonic;
using SubSonic.Utilities;

//Generated on 18/07/2007 15:55:01 by rupert_bates

namespace OpenProject.DataObjects{
    /// <summary>
    /// Strongly-typed collection for the CMSPage class.
    /// </summary>
    [Serializable]
    public partial class CMSPageCollection : ActiveList<CMSPage, CMSPageCollection> 
    {       
        public CMSPageCollection() {}

    }

    /// <summary>
    /// This is an ActiveRecord class which wraps the CMSPage table.
    /// </summary>
    [Serializable]
    public partial class CMSPage : ActiveRecord<CMSPage>
    {
    
	    #region Default Settings
	    protected static void SetSQLProps() 
	    {
		    GetTableSchema();
	    }

	    #endregion
        #region Schema Accessor
	    public static TableSchema.Table Schema
        {
            get
            {
                if (BaseSchema == null)
                {
                    SetSQLProps();
                }

                return BaseSchema;
            }

        }

    	
        private static void GetTableSchema() 
	    {
            if(!IsSchemaInitialized)
            {
                //Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CMSPage", TableType.Table, DataService.GetInstance("OpenProject"));
                schema.Columns = new TableSchema.TableColumnCollection();
                schema.SchemaName = @"dbo";
                //columns
                
                TableSchema.TableColumn colvarPageID = new TableSchema.TableColumn(schema);
                colvarPageID.ColumnName = "PageID";
                colvarPageID.DataType = DbType.Int32;
                colvarPageID.MaxLength = 0;
                colvarPageID.AutoIncrement = true;
                colvarPageID.IsNullable = false;
                colvarPageID.IsPrimaryKey = true;
                colvarPageID.IsForeignKey = false;
                colvarPageID.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarPageID);
                
                TableSchema.TableColumn colvarTitle = new TableSchema.TableColumn(schema);
                colvarTitle.ColumnName = "Title";
                colvarTitle.DataType = DbType.String;
                colvarTitle.MaxLength = 500;
                colvarTitle.AutoIncrement = false;
                colvarTitle.IsNullable = false;
                colvarTitle.IsPrimaryKey = false;
                colvarTitle.IsForeignKey = false;
                colvarTitle.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarTitle);
                
                TableSchema.TableColumn colvarBody = new TableSchema.TableColumn(schema);
                colvarBody.ColumnName = "Body";
                colvarBody.DataType = DbType.String;
                colvarBody.MaxLength = -1;
                colvarBody.AutoIncrement = false;
                colvarBody.IsNullable = true;
                colvarBody.IsPrimaryKey = false;
                colvarBody.IsForeignKey = false;
                colvarBody.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarBody);
                
                TableSchema.TableColumn colvarLocale = new TableSchema.TableColumn(schema);
                colvarLocale.ColumnName = "Locale";
                colvarLocale.DataType = DbType.AnsiStringFixedLength;
                colvarLocale.MaxLength = 7;
                colvarLocale.AutoIncrement = false;
                colvarLocale.IsNullable = false;
                colvarLocale.IsPrimaryKey = false;
                colvarLocale.IsForeignKey = false;
                colvarLocale.IsReadOnly = false;
                
						colvarLocale.DefaultSetting = @"('en-US')";
				
                
                schema.Columns.Add(colvarLocale);
                
                TableSchema.TableColumn colvarParentID = new TableSchema.TableColumn(schema);
                colvarParentID.ColumnName = "ParentID";
                colvarParentID.DataType = DbType.Int32;
                colvarParentID.MaxLength = 0;
                colvarParentID.AutoIncrement = false;
                colvarParentID.IsNullable = true;
                colvarParentID.IsPrimaryKey = false;
                colvarParentID.IsForeignKey = false;
                colvarParentID.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarParentID);
                
                TableSchema.TableColumn colvarPageGuid = new TableSchema.TableColumn(schema);
                colvarPageGuid.ColumnName = "PageGuid";
                colvarPageGuid.DataType = DbType.Guid;
                colvarPageGuid.MaxLength = 0;
                colvarPageGuid.AutoIncrement = false;
                colvarPageGuid.IsNullable = false;
                colvarPageGuid.IsPrimaryKey = false;
                colvarPageGuid.IsForeignKey = false;
                colvarPageGuid.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarPageGuid);
                
                TableSchema.TableColumn colvarMenuTitle = new TableSchema.TableColumn(schema);
                colvarMenuTitle.ColumnName = "MenuTitle";
                colvarMenuTitle.DataType = DbType.String;
                colvarMenuTitle.MaxLength = 50;
                colvarMenuTitle.AutoIncrement = false;
                colvarMenuTitle.IsNullable = false;
                colvarMenuTitle.IsPrimaryKey = false;
                colvarMenuTitle.IsForeignKey = false;
                colvarMenuTitle.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarMenuTitle);
                
                TableSchema.TableColumn colvarSummary = new TableSchema.TableColumn(schema);
                colvarSummary.ColumnName = "Summary";
                colvarSummary.DataType = DbType.String;
                colvarSummary.MaxLength = 500;
                colvarSummary.AutoIncrement = false;
                colvarSummary.IsNullable = true;
                colvarSummary.IsPrimaryKey = false;
                colvarSummary.IsForeignKey = false;
                colvarSummary.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarSummary);
                
                TableSchema.TableColumn colvarPageUrl = new TableSchema.TableColumn(schema);
                colvarPageUrl.ColumnName = "PageUrl";
                colvarPageUrl.DataType = DbType.String;
                colvarPageUrl.MaxLength = 500;
                colvarPageUrl.AutoIncrement = false;
                colvarPageUrl.IsNullable = false;
                colvarPageUrl.IsPrimaryKey = false;
                colvarPageUrl.IsForeignKey = false;
                colvarPageUrl.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarPageUrl);
                
                TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
                colvarCreatedOn.ColumnName = "CreatedOn";
                colvarCreatedOn.DataType = DbType.DateTime;
                colvarCreatedOn.MaxLength = 0;
                colvarCreatedOn.AutoIncrement = false;
                colvarCreatedOn.IsNullable = false;
                colvarCreatedOn.IsPrimaryKey = false;
                colvarCreatedOn.IsForeignKey = false;
                colvarCreatedOn.IsReadOnly = false;
                
						colvarCreatedOn.DefaultSetting = @"(getdate())";
				
                
                schema.Columns.Add(colvarCreatedOn);
                
                TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
                colvarCreatedBy.ColumnName = "CreatedBy";
                colvarCreatedBy.DataType = DbType.String;
                colvarCreatedBy.MaxLength = 50;
                colvarCreatedBy.AutoIncrement = false;
                colvarCreatedBy.IsNullable = true;
                colvarCreatedBy.IsPrimaryKey = false;
                colvarCreatedBy.IsForeignKey = false;
                colvarCreatedBy.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarCreatedBy);
                
                TableSchema.TableColumn colvarModifiedOn = new TableSchema.TableColumn(schema);
                colvarModifiedOn.ColumnName = "ModifiedOn";
                colvarModifiedOn.DataType = DbType.DateTime;
                colvarModifiedOn.MaxLength = 0;
                colvarModifiedOn.AutoIncrement = false;
                colvarModifiedOn.IsNullable = false;
                colvarModifiedOn.IsPrimaryKey = false;
                colvarModifiedOn.IsForeignKey = false;
                colvarModifiedOn.IsReadOnly = false;
                
						colvarModifiedOn.DefaultSetting = @"(getdate())";
				
                
                schema.Columns.Add(colvarModifiedOn);
                
                TableSchema.TableColumn colvarModifiedBy = new TableSchema.TableColumn(schema);
                colvarModifiedBy.ColumnName = "ModifiedBy";
                colvarModifiedBy.DataType = DbType.String;
                colvarModifiedBy.MaxLength = 50;
                colvarModifiedBy.AutoIncrement = false;
                colvarModifiedBy.IsNullable = true;
                colvarModifiedBy.IsPrimaryKey = false;
                colvarModifiedBy.IsForeignKey = false;
                colvarModifiedBy.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarModifiedBy);
                
                TableSchema.TableColumn colvarDeleted = new TableSchema.TableColumn(schema);
                colvarDeleted.ColumnName = "Deleted";
                colvarDeleted.DataType = DbType.Boolean;
                colvarDeleted.MaxLength = 0;
                colvarDeleted.AutoIncrement = false;
                colvarDeleted.IsNullable = false;
                colvarDeleted.IsPrimaryKey = false;
                colvarDeleted.IsForeignKey = false;
                colvarDeleted.IsReadOnly = false;
                
						colvarDeleted.DefaultSetting = @"((0))";
				
                
                schema.Columns.Add(colvarDeleted);
                
                TableSchema.TableColumn colvarProjectId = new TableSchema.TableColumn(schema);
                colvarProjectId.ColumnName = "ProjectId";
                colvarProjectId.DataType = DbType.Int32;
                colvarProjectId.MaxLength = 0;
                colvarProjectId.AutoIncrement = false;
                colvarProjectId.IsNullable = true;
                colvarProjectId.IsPrimaryKey = false;
                colvarProjectId.IsForeignKey = true;
                colvarProjectId.IsReadOnly = false;
                
                
				colvarProjectId.ForeignKeyTableName = "Project";
                
                schema.Columns.Add(colvarProjectId);
                
                BaseSchema = schema;
                //add this schema to the provider
                //so we can query it later
                DataService.Providers["OpenProject"].AddSchema("CMSPage",schema);
            }

        }

        #endregion
        
        #region Query Accessor
	    public static Query CreateQuery()
	    {
		    return new Query(Schema);
	    }

	    #endregion
	    
	    #region .ctors
	    public CMSPage()
	    {
            SetSQLProps();
            SetDefaults();
            MarkNew();
        }

        
        public CMSPage(bool useDatabaseDefaults)
	    {
		    SetSQLProps();
		    if(useDatabaseDefaults)
		    {
				ForceDefaults();
			}

			MarkNew();
	    }

	    public CMSPage(object keyID)
	    {
		    SetSQLProps();
            SetDefaults();
		    LoadByKey(keyID);
	    }

    	 
	    public CMSPage(string columnName, object columnValue)
        {
            SetSQLProps();
            SetDefaults();
            LoadByParam(columnName,columnValue);
        }

        
	    #endregion
	    
	    #region Props
	    
          
        [XmlAttribute("PageID")]
        public int PageID 
	    {
		    get { return GetColumnValue<int>("PageID"); }

            set 
		    {
			    SetColumnValue("PageID", value);
            }

        }

	      
        [XmlAttribute("Title")]
        public string Title 
	    {
		    get { return GetColumnValue<string>("Title"); }

            set 
		    {
			    SetColumnValue("Title", value);
            }

        }

	      
        [XmlAttribute("Body")]
        public string Body 
	    {
		    get { return GetColumnValue<string>("Body"); }

            set 
		    {
			    SetColumnValue("Body", value);
            }

        }

	      
        [XmlAttribute("Locale")]
        public string Locale 
	    {
		    get { return GetColumnValue<string>("Locale"); }

            set 
		    {
			    SetColumnValue("Locale", value);
            }

        }

	      
        [XmlAttribute("ParentID")]
        public int? ParentID 
	    {
		    get { return GetColumnValue<int?>("ParentID"); }

            set 
		    {
			    SetColumnValue("ParentID", value);
            }

        }

	      
        [XmlAttribute("PageGuid")]
        public Guid PageGuid 
	    {
		    get { return GetColumnValue<Guid>("PageGuid"); }

            set 
		    {
			    SetColumnValue("PageGuid", value);
            }

        }

	      
        [XmlAttribute("MenuTitle")]
        public string MenuTitle 
	    {
		    get { return GetColumnValue<string>("MenuTitle"); }

            set 
		    {
			    SetColumnValue("MenuTitle", value);
            }

        }

	      
        [XmlAttribute("Summary")]
        public string Summary 
	    {
		    get { return GetColumnValue<string>("Summary"); }

            set 
		    {
			    SetColumnValue("Summary", value);
            }

        }

	      
        [XmlAttribute("PageUrl")]
        public string PageUrl 
	    {
		    get { return GetColumnValue<string>("PageUrl"); }

            set 
		    {
			    SetColumnValue("PageUrl", value);
            }

        }

	      
        [XmlAttribute("CreatedOn")]
        public DateTime CreatedOn 
	    {
		    get { return GetColumnValue<DateTime>("CreatedOn"); }

            set 
		    {
			    SetColumnValue("CreatedOn", value);
            }

        }

	      
        [XmlAttribute("CreatedBy")]
        public string CreatedBy 
	    {
		    get { return GetColumnValue<string>("CreatedBy"); }

            set 
		    {
			    SetColumnValue("CreatedBy", value);
            }

        }

	      
        [XmlAttribute("ModifiedOn")]
        public DateTime ModifiedOn 
	    {
		    get { return GetColumnValue<DateTime>("ModifiedOn"); }

            set 
		    {
			    SetColumnValue("ModifiedOn", value);
            }

        }

	      
        [XmlAttribute("ModifiedBy")]
        public string ModifiedBy 
	    {
		    get { return GetColumnValue<string>("ModifiedBy"); }

            set 
		    {
			    SetColumnValue("ModifiedBy", value);
            }

        }

	      
        [XmlAttribute("Deleted")]
        public bool Deleted 
	    {
		    get { return GetColumnValue<bool>("Deleted"); }

            set 
		    {
			    SetColumnValue("Deleted", value);
            }

        }

	      
        [XmlAttribute("ProjectId")]
        public int? ProjectId 
	    {
		    get { return GetColumnValue<int?>("ProjectId"); }

            set 
		    {
			    SetColumnValue("ProjectId", value);
            }

        }

	    
	    #endregion
	    
	    
	 	
			
	    
	    
	    
	    #region ForeignKey Properties
	    
        /// <summary>
        /// Returns a Project ActiveRecord object related to this CMSPage
        /// 
        /// </summary>
	    public OpenProject.DataObjects.Project Project
        {
	        get { return OpenProject.DataObjects.Project.FetchByID(this.ProjectId); }

	        set
	        {
	        	SetColumnValue("ProjectId", value.ProjectId);
		        //SetColumnValue("ProjectId", value.ProjectId);
	        }

        }

	    
	    
	    #endregion
	    
	    
	    
	    //no ManyToMany tables defined (0)
	    
	    #region ObjectDataSource support
    	
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
	    public static void Insert(string varTitle,string varBody,string varLocale,int? varParentID,Guid varPageGuid,string varMenuTitle,string varSummary,string varPageUrl,DateTime varCreatedOn,string varCreatedBy,DateTime varModifiedOn,string varModifiedBy,bool varDeleted,int? varProjectId)
	    {
		    CMSPage item = new CMSPage();
		    
            item.Title = varTitle;
            
            item.Body = varBody;
            
            item.Locale = varLocale;
            
            item.ParentID = varParentID;
            
            item.PageGuid = varPageGuid;
            
            item.MenuTitle = varMenuTitle;
            
            item.Summary = varSummary;
            
            item.PageUrl = varPageUrl;
            
            item.CreatedOn = varCreatedOn;
            
            item.CreatedBy = varCreatedBy;
            
            item.ModifiedOn = varModifiedOn;
            
            item.ModifiedBy = varModifiedBy;
            
            item.Deleted = varDeleted;
            
            item.ProjectId = varProjectId;
            
	    
		    if (System.Web.HttpContext.Current != null)
			    item.Save(System.Web.HttpContext.Current.User.Identity.Name);
		    else
			    item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
	    public static void Update(int varPageID,string varTitle,string varBody,string varLocale,int? varParentID,Guid varPageGuid,string varMenuTitle,string varSummary,string varPageUrl,DateTime varCreatedOn,string varCreatedBy,DateTime varModifiedOn,string varModifiedBy,bool varDeleted,int? varProjectId)
	    {
		    CMSPage item = new CMSPage();
		    
                item.PageID = varPageID;
				
                item.Title = varTitle;
				
                item.Body = varBody;
				
                item.Locale = varLocale;
				
                item.ParentID = varParentID;
				
                item.PageGuid = varPageGuid;
				
                item.MenuTitle = varMenuTitle;
				
                item.Summary = varSummary;
				
                item.PageUrl = varPageUrl;
				
                item.CreatedOn = varCreatedOn;
				
                item.CreatedBy = varCreatedBy;
				
                item.ModifiedOn = varModifiedOn;
				
                item.ModifiedBy = varModifiedBy;
				
                item.Deleted = varDeleted;
				
                item.ProjectId = varProjectId;
				
		    item.IsNew = false;
		    if (System.Web.HttpContext.Current != null)
			    item.Save(System.Web.HttpContext.Current.User.Identity.Name);
		    else
			    item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
	    }

	    #endregion
	    #region Columns Struct
	    public struct Columns
	    {
		    
		    
            public static string PageID = @"PageID";
            
            public static string Title = @"Title";
            
            public static string Body = @"Body";
            
            public static string Locale = @"Locale";
            
            public static string ParentID = @"ParentID";
            
            public static string PageGuid = @"PageGuid";
            
            public static string MenuTitle = @"MenuTitle";
            
            public static string Summary = @"Summary";
            
            public static string PageUrl = @"PageUrl";
            
            public static string CreatedOn = @"CreatedOn";
            
            public static string CreatedBy = @"CreatedBy";
            
            public static string ModifiedOn = @"ModifiedOn";
            
            public static string ModifiedBy = @"ModifiedBy";
            
            public static string Deleted = @"Deleted";
            
            public static string ProjectId = @"ProjectId";
            
	    }

	    #endregion
    }

}

